package com.wc.alorithm_blue_bridge._简单题.三带一;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Author congge
 * @Date 2024/4/8 21:43
 * @description https://www.lanqiao.cn/problems/5127/learning/?page=1&first_category_id=1&second_category_id=15
 */
public class Main {
    static int t;
    static char[] s;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        t = sc.nextInt();
        while (t-- > 0) {
            s = (" " + sc.next()).toCharArray();
            Arrays.sort(s, 1, 5);
            if (s[1] == s[2] && s[2] == s[3] && s[3] != s[4] || s[1] != s[2] && s[2] == s[3] && s[3] == s[4]) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
}
